#include <fcntl.h>
#include <unistd.h>
#include <iostream>
using namespace std;
int main()
{
    int fd = 0;
    //获取标志符
    int fn = fcntl(fd, F_GETFL);
    //增加O_NONBLOCK并设置
    fcntl(fd, F_SETFL, fn | O_NONBLOCK);
    int count = 0;
    while(1)
    {
        char buffer[1024];
        int n = read(fd, buffer, sizeof(buffer)-1);
        if(n > 0)
        {
            buffer[n] = '\0';
            cout<<buffer<<endl;
            sleep(1);
        }
        else if(n < 0)
        {
            if(EAGAIN || errno == EWOULDBLOCK)
            {
                cout<<"文件未就绪..."<<endl;
                sleep(2);
            }
            else if(errno == EINTR)
            {
                cout<<"信号中断..."<<endl;
                continue;
            }
            else
            {
                perror("read fail\n");
                break
            }
        }
        else
        {
            break;
        }
    }
    return 0;
}